﻿
namespace Huirui.Cavan.Domain.MainBoundedContext.SystemModule
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Huirui.Cavan.Core.Attribute;
    using System.Reflection;

    public class SystemIdentifier
    {
        public enum Role
        {
            [Name("系统管理员")]
            SystemAdministrator = 1,
            [Name("销售员")]
            Seller = 2,
            [Name("采购员")]
            Purchaser = 3,
            [Name("仓库管理员")]
            WareHouseManager = 4
        }

        public enum ShowPattern
        {
            Text = 1,
            Image = 2,
            TextAndImage = 3
        }

        public enum TimeRange
        {
            Day = 1,
            Week = 2
        }

        public enum NoticeType
        {
            Important = 1,
            Normal = 2
        }

        public enum AccountType
        {
            [Name("现金")]
            Cash = 1,
            [Name("银行账户")]
            Deposit = 2,
            [Name("费用")]
            Cost = 3
        }

        public enum AccountStatus
        {
            [Name("使用中")]
            Using = 1,
            [Name("停用中")]
            Invalid = 2
        }

        public enum BaseCodeRuleType
        {
            [Name("供应商")]
            Supplier = 1,
            [Name("客户")]
            Customer = 2,
            [Name("部门")]
            Department = 3,
            [Name("职员")]
            Employee = 4,
            [Name("存货")]
            Stock = 5,
            [Name("项目")]
            Project = 6,
            [Name("帐号")]
            Account = 7
        }

        public enum ReceiptCodeRuleType
        {
            [Name("付款单")]
            Pay = 1,
            [Name("采购订单")]
            PurchaseOrder = 2,
            [Name("费用支出单")]
            PurchaseFee = 3,
            [Name("采购单")]
            Purchase = 4,
            [Name("采购退货单")]
            PurchaseReturn = 5,
            [Name("其他应收单")]
            OtherReceivable = 6,
            [Name("销售订单")]
            SalesOrder = 7,
            [Name("收款单")]
            Receipt = 8,
            [Name("销售单")]
            Sale = 9,
            [Name("销售退货单")]
            SalesReturn = 10,
            [Name("其他入库单")]
            StockIn = 11,
            [Name("其他出货单")]
            StockOut = 12,
            [Name("其他出库申请单")]
            StockOutApply = 13,
            [Name("存货调拨单")]
            StockAllocate = 14,
            [Name("存货转换单")]
            StockExchange = 15,
            [Name("销售价格单")]
            SalesPrice = 16,
            [Name("存货盘点")]
            StockCheck = 17
        }

        public enum EmployeeType
        {
            [Name("销售员")]
            Saler = 1,
            [Name("采购员")]
            Purchaser = 2,
            [Name("仓库管理员")]
            StockManager = 3,
            [Name("其他")]
            Other = 4
        }

        public enum CodePattern
        {
            [Name("流水号")]
            SerialNumber = 1,
            [Name("年编号")]
            Year = 2,
            [Name("月编号")]
            Month = 3,
            [Name("日编号")]
            Day = 4
        }

        public enum SystemConfigType
        {
            [Name("公共")]
            Public = 1,
            [Name("费用")]
            Fee = 2,
            [Name("存货")]
            Stock = 3
        }

        public enum DataType
        {
            Int = 1,
            Decimal = 2,
            String = 3,
            Bool = 4,
            DateTime = 5
        }

        public enum CustomerNature
        {
            [Name("客户")]
            Customer = 1,
            [Name("既是客户又是供应商")]
            CustomerAndSupplier = 2
        }

        public enum AgentType
        {
            [Name("批发商")]
            Wholesalers = 1,
            [Name("一级代理")]
            Level1 = 2,
            [Name("二级代理")]
            Level2 = 3
        }

        public enum PayType
        {
            [Name("(空)")]
            None = 0,
            [Name("现金")]
            Cash = 1,
            [Name("支票")]
            Check = 2,
            [Name("信用卡")]
            CreditCard = 3,
            [Name("银行转帐")]
            BankTransfer = 4
        }

        public enum InvoiceType
        {
            [Name("普通发票")]
            Normal = 1,
            [Name("增值发票")]
            Increase = 2,
            [Name("收据")]
            Receipt = 3
        }

        public enum CodeRuleType
        {
            Base = 1,
            Receipt = 2
        }

        public enum Sex
        {
            [Name("男")]
            Male = 1,
            [Name("女")]
            Female = 2
        }

        public enum SMSQueryEnabledStatus
        {
            [Name("未开启")]
            Close = 0,
            [Name("已开启")]
            Open = 1
        }

        public enum WareHouseStatus
        {
            [Name("使用中")]
            Using = 1,
            [Name("停用中")]
            Invalid = 2
        }

        public enum SupplierNature
        {
            [Name("供应商")]
            Supplier = 1,
            [Name("既是供应商又是客户")]
            SupplierAndCustomer = 2
        }

        public enum DefaultStockInOutType
        {
            [Name("其他入库")]
            Other = 1,
            [Name("盘盈")]
            InventoryProfit = 2,
            [Name("产成品入库")]
            Purchase = 3,
            [Name("借出转销售")]
            Sales = 4,
            [Name("采购退货")]
            PurchaseReturn = 5
        }

        public enum CheckedStatus
        {
            [Name("未审核")]
            UnChecked = 0,
            [Name("通过")]
            Pass = 1,
            [Name("不通过")]
            Fail = 2
        }

        public enum InitialType
        {
            [Name("应收账款")]
            AccountsReceivable = 1,
            [Name("预收账款")]
            DepositReceived = 2,
            [Name("其他应收账款")]
            OtherReceivable = 3,
            [Name("应付账款")]
            AccountsPayable = 4,
            [Name("预付账款")]
            DepositPay = 5,
            [Name("其他应付账款")]
            OtherPay = 6,
        }

        public enum StockPriceMethod
        {
            [Name("先进先出法")]
            FirstInFirstOut = 1,
            [Name("月加权平均法")]
            MonthAverage = 2,
            [Name("移动平均法")]
            MoveAverage = 3,
            [Name("取标准买价")]
            StandardPurchase = 4
        }

        public enum PermissionType
        {
            Operation = 1,
            Data = 2
        }

        private static List<MyEnumeInfo> enumList = null;
        public static List<MyEnumeInfo> EnumList
        {
            get
            {
                return SystemIdentifier.GetMyEnumeInfo();
            }
        }

        private static List<MyEnumeInfo> GetMyEnumeInfo()
        {
            if (enumList == null || enumList.Count == 0)
            {
                enumList = new List<MyEnumeInfo>();

                Type[] plist = typeof(SystemIdentifier).GetNestedTypes(BindingFlags.Public).Where(r => r.IsEnum).ToArray();
                foreach (Type type in plist)
                {
                    foreach (var value in Enum.GetValues(type))
                    {
                        MyEnumeInfo nkv = new MyEnumeInfo();
                        nkv.EnumeName = type.Name;
                        nkv.Value = ((int)value).ToString();
                        nkv.Key = Enum.GetName(type, value);
                        object[] attrArray = type.GetField(nkv.Key).GetCustomAttributes(typeof(NameAttribute), false);
                        nkv.AttriName = attrArray.Length > 0 ? ((NameAttribute)attrArray[0]).Name : nkv.Key;
                        enumList.Add(nkv);
                    }
                }
            }
            return enumList;
        }

        public static string GetAttrName(string strName, string key)
        {
           return EnumList.Where(r => r.EnumeName == strName && r.Key == key).Select(r => r.AttriName).FirstOrDefault();
        }

    }

    public class MyEnumeInfo
    {
        public string EnumeName { get; set; }
        public string AttriName { get; set; }
        public string Key { get; set; }
        public string Value { get; set; }

        public MyEnumeInfo()
        {
            // TODO: Complete member initialization
        }
    }

}
